package com.modelo.dao.empresa;

import java.util.List;

import org.hibernate.LockMode;
import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.modelo.dao.comun.HibernateBaseDAO;
import com.modelo.entity.Documento;
import com.modelo.entity.Empresa;

@Repository
public class EmpresaDAO extends HibernateBaseDAO<Empresa> implements IEmpresaDAO {
	private static final Logger log = LoggerFactory.getLogger(EmpresaDAO.class);
	 
	public static final String VISTO = "visto";

	protected void initDao() {
	 
	}

	 @Autowired  
	 public EmpresaDAO(SessionFactory sessionFactory) {  
	        super(sessionFactory);  
	 } 
	 
	public List<Empresa> findByExample(Empresa instance) {
		log.debug("finding Empresa instance by example");
		try {
			List<Empresa> results = (List<Empresa>) getHibernateTemplate()
					.findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Empresa instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Empresa as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<Empresa> findByVisto(Object visto) {
		return findByProperty(VISTO, visto);
	}

	public static EmpresaDAO getFromApplicationContext(ApplicationContext ctx) {
		return (EmpresaDAO) ctx.getBean("EmpresaDAO");
	}
}